﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Net.Mail;

public class Operations
{
    public static SmtpClient Client = new SmtpClient();
    static MailAddress from = new MailAddress("info@beklans.com", "Expense Tracker Admin");
    static MailAddress cc = new MailAddress("alanjebakumar@beklans.com", "Alan Jebakumar");
    static MailAddress SendTo;
    static MailMessage msg;
    static System.Net.NetworkCredential basicInfo = new System.Net.NetworkCredential("info@beklans.com", "beklansAdmin");
    
    public static string EmailRecoveredPassword(string DisplayName, string SecAnswer, string CorrectPassword, string eMailAddress)
    {
        SendTo = new MailAddress(eMailAddress);
        msg = new MailMessage(from, SendTo);
        Client.Host = "smtpout.asia.secureserver.net";
        Client.Port = 80;
        Client.UseDefaultCredentials = false;
        Client.Credentials = basicInfo;
        string DecryptedPass = SSTCryptographer.Decrypt(CorrectPassword, System.Web.Configuration.WebConfigurationManager.AppSettings["KEY"]);
        MailAddress recepient = new MailAddress(eMailAddress);
        msg.Bcc.Add(cc);
        msg.Priority = MailPriority.High;
        msg.IsBodyHtml = true;
        msg.Subject = "Recovered Password";
        msg.Body = "Hi " + DisplayName + "<br/><br/>Your Recovered Password for the account " + DisplayName + " is: <b>" + DecryptedPass + "</b><br/><br/>Regards,<br/>ExpenseTracker Admin Team.";
        try
        {
            Client.Send(msg);
        }
        catch (HttpException ex)
        {
            return ex.Message;
        }
        catch (SmtpException ex)
        {
            return ex.Message;
        }
        finally
        {
            msg.Dispose();
        }
        return null;
    }
    public static string EmailNewAccountCreated(string DisplayName)
    {
        SendTo = new MailAddress("alanjebakumar@beklans.com", "Expense Tracker Info");
        msg = new MailMessage(from, SendTo);
        Client.Host = "smtpout.asia.secureserver.net";
        Client.Port = 80;
        Client.Credentials = basicInfo;
        msg.Priority = MailPriority.High;
        msg.IsBodyHtml = true;
        msg.Subject = "New Account Created";
        msg.Body = "Hi Admin,<br/> A new account has been created with the account name '" + DisplayName + "'. Kindly activate the account.<br/><br/>Regards,<br/>Expense Tracker.";
        try
        {
            Client.Send(msg);
        }
        catch (SmtpException ex)
        {
            return ex.Message;
        }
        return null;
    }
}